
package javadateoperation;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class JavaDateOperation {

    public static void main(String[] args) {
 
        //定义时间格式
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date date = new Date();
        //输出当前时间    
        System.out.println("now:"+format.format(date));
        //获得Calendar实例
        Calendar calendar = Calendar.getInstance();
        //把要进行运算的时间放到calendar实例中
        calendar.setTime(date);
        //进行运算
        //去年
        calendar.add(Calendar.YEAR,-1);
        System.out.println("last year:"+format.format(calendar.getTime()));

       
    }
    
}
